package com.woniuxy.dao;

import com.woniuxy.pojo.MerchantAuth;
import com.woniuxy.pojo.MerchantUsers;
import com.woniuxy.pojo.User;
import com.woniuxy.pojo.UserMerchant;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface MerchantUsersMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(MerchantUsers record);

    int insertSelective(MerchantUsers record);

    MerchantUsers selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(MerchantUsers record);

    int updateByPrimaryKey(MerchantUsers record);
    @Select("select count(1) from mcar_parking where pid=#{pid} ")
    Integer selectCarNums(Integer pid);
    @Select("select count(1) from mcar_parking where pid=#{pid} and state=1 and u_state=0 and p_state=0")
    Integer selectCarNumson(Integer pid);
    @Select("select count(1) from mcar_parking where pid=#{pid} and p_state=1")
    Integer selectCarNumsdo(Integer pid);
    @Insert("insert into merchant_users(m_name,m_phoneNum,m_password,regtime) values(#{mName},#{mPhonenum},#{mPassword},#{regtime})")
    void addpUser(MerchantUsers users);
    @Insert("insert into merchant_auth(m_id,m_address,m_licensenum,m_positive,m_side,lnglat,m_name) values(" +
            "#{mId},#{mAddress},#{mLicensenum},#{mPositive},#{mSide},#{lnglat},#{mName})")
    void register(MerchantAuth users);
    @Select("select * from user where username=#{mPhonenum}")
    User findUserByTel(String mPhonenum);
    @Select("select * from merchant_users where id=(select pid from user_merchant where uid=#{id})")
    MerchantUsers findPuserByid(Integer id);
    @Update("update merchant_users set cash_advance=#{cashAdvance} where id=#{id}")
    void updatebalence(MerchantUsers merchantUsers);
   @Update("update merchant_users set balance=balance-#{cashAdvance} where id=#{id}")
    void Confirm(MerchantUsers merchantUsers);
    @Update("update merchant_users set cash_advance =0 where id=#{id}")
    void rollback(MerchantUsers merchantUsers);

   @Select("select * from merchant_users where m_phoneNum =#{mPhonenum}")
    MerchantUsers findMerchantuser(MerchantUsers users);
   @Insert("insert into user_merchant(uid,pid) values(#{uid},#{pid})")
    void insertUM(UserMerchant userMerchant);
}